package com.jic.data.controller;

import com.jic.data.model.entity.DiscountRate;
import com.jic.data.model.entity.SaleStructureData;
import com.jic.data.model.vo.request.SaleDiscountRateRequest;
import com.jic.data.model.vo.request.SaleStructureDataRequest;
import com.jic.data.model.vo.response.HistogramChartResponse;
import com.jic.data.model.vo.response.SaleDiscountRateResponse;
import com.jic.data.model.vo.response.SaleStructureDataResponse;
import com.jic.data.service.SaleDiscountRateService;
import com.jic.data.service.SaleStructureDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

import com.jic.common.base.vo.RestResult;
import lombok.extern.slf4j.Slf4j;
import com.jic.data.model.vo.request.SaleStructureBaseDataRequest;
import com.jic.data.model.vo.response.SaleStructureBaseDataResponse;
import com.jic.data.model.entity.SaleStructureBaseData;
import com.jic.data.service.SaleStructureBaseDataService;

/**
 * @Author: 建投数据科技(山东)有限公司
 * @date: 2020-05-09 17:25:19
 */
@RestController
@Slf4j
@RequestMapping("/saleStructureBaseData")
@Api(tags = " [销售结构-销售结构基础数据]控制类-PC")
public class SaleStructureBaseDataController {
    @Autowired
    private SaleStructureBaseDataService baseDataService;

    @Autowired
    private SaleStructureDataService dataService;

    @Autowired
    private SaleDiscountRateService saleSourceService;



    // TODO 修改完成
    @PostMapping("/list/all")
    @ApiOperation(value = "销售结构-销售结构基础数据")
    @ResponseBody
    public RestResult<SaleStructureBaseDataResponse> listSaleStructureBaseDataAllRecord(@RequestBody SaleStructureBaseDataRequest request) throws Throwable {
        SaleStructureBaseData saleStructureBaseData = new SaleStructureBaseData();
        BeanUtils.copyProperties(request, saleStructureBaseData);
        SaleStructureBaseData baseData = baseDataService.listAllRecord(saleStructureBaseData);
        SaleStructureBaseDataResponse response = new SaleStructureBaseDataResponse();
        BeanUtils.copyProperties(baseData, response);
        return RestResult.success(response);
    }


    // TODO 修改完成
    @PostMapping("/list/sale/amount")
    @ApiOperation(value = "销售结构：销售来源_会员/非会员 (销售额)")
    @ResponseBody
    public RestResult<HistogramChartResponse> querySaleAmount(@RequestBody SaleStructureBaseDataRequest request) throws Throwable {
        SaleStructureBaseData saleStructureBaseData = new SaleStructureBaseData();
        BeanUtils.copyProperties(request, saleStructureBaseData);
        HistogramChartResponse response = baseDataService.selectSaleAmount(saleStructureBaseData);
        return RestResult.success(response);
    }

    // TODO 修改完成
    @PostMapping("/list/sale/order")
    @ApiOperation(value = "销售结构： 订单分布 （每天订单数）)")
    @ResponseBody
    public RestResult<HistogramChartResponse> queryTotalOrder(@RequestBody SaleStructureBaseDataRequest request) throws Throwable {
        SaleStructureBaseData saleStructureBaseData = new SaleStructureBaseData();
        BeanUtils.copyProperties(request, saleStructureBaseData);
        HistogramChartResponse response = baseDataService.selectTotalOrder(saleStructureBaseData);
        return RestResult.success(response);
    }


    // TODO 修改完成
    @PostMapping("/list/discount")
    @ApiOperation(value = "销售结构-折扣率趋势 ")
    @ResponseBody
    public RestResult<HistogramChartResponse> listSaleSourceAllRecord(@RequestBody SaleDiscountRateRequest request) throws Throwable {
        DiscountRate saleSource = new DiscountRate();
        BeanUtils.copyProperties(request, saleSource);
        HistogramChartResponse response = saleSourceService.listAllRecord(saleSource);

        return RestResult.success(response);
    }


    // TODO 修改完成
    @PostMapping("/list/detail/data")
    @ApiOperation(value = "[销售结构-销售结构明细数据]")
    @ResponseBody
    public RestResult<List<SaleStructureDataResponse>> listSaleStructureDataAllRecord(@RequestBody SaleStructureDataRequest request) throws Throwable {
        SaleStructureData saleStructureData = new SaleStructureData();
        BeanUtils.copyProperties(request, saleStructureData);
        List<SaleStructureDataResponse> responseList = dataService.listAllRecord(saleStructureData);

        return RestResult.success(responseList);
    }






}

